package com.kfm.login.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.kfm.login.mapper.KfmUserMapper;
import com.kfm.login.model.KfmUser;
import com.kfm.login.service.KfmUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class KfmUserServiceImpl implements KfmUserService {

    @Resource
    private KfmUserMapper kfmUserMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return kfmUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(KfmUser record) {
        record.setPassword(SecureUtil.md5(record.getPassword()));
        return kfmUserMapper.insert(record);
    }

    @Override
    public int insertSelective(KfmUser record) {
        return kfmUserMapper.insertSelective(record);
    }

    @Override
    public KfmUser selectByPrimaryKey(Integer id) {
        return kfmUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(KfmUser record) {
        return kfmUserMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(KfmUser record) {
        return kfmUserMapper.updateByPrimaryKey(record);
    }

    @Override
    public KfmUser login(String username, String password) {
        return kfmUserMapper.selectByUsernameAndPassword(username, SecureUtil.md5(password));
    }

    @Override
    public KfmUser login2(String username, String password) {
        return kfmUserMapper.selectByUsernameAndPassword(username, password);
    }

    @Override
    public KfmUser findByUsername(String username) {
        return kfmUserMapper.selectByUsername(username);
    }

}
